<?php

/**
 * 用户中心
 * @author yjmp
*/

define('IN_ECS', true);
define('ECS_ADMIN', true);

require(dirname(__FILE__) . '/includes/init.php');
require(dirname(__FILE__) . '/includes/lib_index.php');
require(dirname(__FILE__) . '/includes/auto_login.php');
require(dirname(__FILE__) . '/includes/wx_option.php');


/*用户数据*/
$user_info = $GLOBALS['db']->getRow('SELECT * FROM '.$GLOBALS['ecs']->table('users').' WHERE wecha_id = "'.$_SESSION['openids'].'"');
if ($user_info) {
    $smarty->assign('user_info',$user_info);
}


//用户信息
elseif ($act == 'user_profile') {
    $smarty->assign('user_profile',1);
    $sub_count = $GLOBALS['db']->getOne('SELECT COUNT(*) FROM '.$GLOBALS['ecs']->table('users').' WHERE parent_id = "'.$user_info['user_id'].'"');
    $smarty->assign('sub_count',$sub_count);
    $smarty->display('user_profile.dwt');exit;
}

//推广二维码
elseif ($act == 'extension') {
    //参数为场景码
    $qr_img = get_qr_img(233);
    $smarty->assign('qr_img',$qr_img);
    $smarty->display('extension.dwt');exit;
}

//我的粉丝
elseif ($act == 'my_fans') {
    $smarty->display('my_fans.dwt');exit;
}//我要赚钱静态 
elseif ($act == 'earn_money') {
    $smarty->display('earn_money.dwt');exit;
}
//商店详情静态
elseif ($act == 'shop_detail') {
    $smarty->display('shop_detail.dwt');exit;
}
/*用户的消费明细*/
elseif ($act == 'sale_detail') {
    $sale_detail = $GLOBALS['db']->getAll('SELECT * FROM '.$GLOBALS['ecs']->table('sales_log').' WHERE user_id = "'.$user_info['user_id'].'" and is_paid = 1');
    foreach ($sale_detail as $k => $v) {
       $sale_detail[$k]['date_format'] =  date('Y-m-d',$v['add_time']);
       $sale_detail[$k]['shop_name'] = $GLOBALS['db']->getOne('SELECT goods_name FROM '.$GLOBALS['ecs']->table('goods').' WHERE goods_id = "'.$v['shop_id'].'"');
    }
    $smarty->assign('sale_details',$sale_detail);
    $smarty->assign('sale_detail',1);
    $smarty->display('user_profile.dwt');exit;
}
/*用户推荐下线*/
elseif ($act == 'rec_list') {
    $smarty->assign('rec_list',1);
    $sub_user_list = $GLOBALS['db']->getAll('SELECT * FROM '.$GLOBALS['ecs']->table('users').' WHERE parent_id = "'.$user_info['user_id'].'"');
    foreach ($sub_user_list as $k => $v) {
        $sub_user_list[$k]['reg_time_format'] = date('Y-m-d',$sub_user_list[$k]['reg_time']);
    }
    $smarty->assign('sub_list',$sub_user_list);
    $smarty->display('user_profile.dwt');exit;
}
/*用户提现界面*/
elseif ($act == 'get_cash') {
    $smarty->assign('get_cash',1);
    $smarty->display('user_profile.dwt');exit;
}

elseif ($act == 'act_get_cash') {
    $money = $_POST['domoney'];
    var_dump($money);exit;
}
?>
